
//Function to call when the script first loads
function init(){
	loadFriends();
}

function loadFriends(){
	var req = opensocial.newDataRequest();
	req.add(req.newFetchPersonRequest('VIEWER','viewer'));
	req.add(req.newFetchPeopleRequest('VIEWER_FRIENDS','viewerFriends'));
	req.send(onLoadFriends);
}

function onLoadFriends(data){
	var viewer = data.getData('viewer').getData();
	var viewerFriends = data.getData('viewerFriends').getData();
	html = new Array();
	html.push('<ul>');
	viewerFriends.each(function(person)){
		html.push('<li>'+person.getDisplayName()+'</li>);
	}
	html.push('</ul>');
	document.getElementById('friends').innerHtml = html.join();
}
